<?php

class ExclusivesController extends GxController {

    public function actionIndex() {
        $cs = Yii::app()->clientScript;
        $cs->scriptMap = array('jquery-1.11.0.min.js' => false,);
        $allClassCourseInfo = array();
        if (isset($_GET['type']) && $_GET['type'] == 'course') {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = runningCurrentCoursesByUser('', '', $_GET);
                usort($allClassCourseInfo, 'date_compare');
            }
        } elseif (isset($_GET['type']) && ($_GET['type'] == 'workshop' OR $_GET['type'] == 'curatedclasses')) {
            if (isset($_GET['priceorder']) OR isset($_GET['mostpopular'])) {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
                $comapreFunction = ($_GET['priceorder'] == '1' ? 'price_compare_ascending' : ($_GET['priceorder'] == '2' ? 'price_compare_descending' : ($_GET['mostpopular'] == '1' ? 'hitcounter_compare_descending' : 'hitcounter_compare_ascending')));
                usort($allClassCourseInfo, $comapreFunction);
            } else {
                $allClassCourseInfo = literalEndingTommorow('', '', $_GET);
            }
        } else {
            $curatedArray = array('type' => 'curatedclasses');
            $classDetails = literalEndingTommorow('', '', $curatedArray);
            $classDetails = array_map('unserialize', array_unique(array_map('serialize', $classDetails)));
            $allClassCourseInfo = $classDetails;
            usort($allClassCourseInfo, 'date_compare');
        }
        $dataProvider = new CArrayDataProvider($allClassCourseInfo, array(
            'sort' => array(
                'attributes' => array(
                    'start_date',
                ),
            ),
            'pagination' => array(
                'pageSize' => 9,
            ),
        ));


        $this->render('//classes/_exclusives', array('dataProvider' => $dataProvider));
    }

}

?>
